package addon.w3.mdx.com;

import java.io.IOException;

import addon.w3.mdx.MDXCOM;
import addon.w3.mdx.LEDataInputStream;
import addon.w3.mdx.MDXException;
import addon.w3.mdx.MDXParentCOM;
/**
 * LAYS						// [Layer}
	long	nlays;
	struct {
		long	nbytesi;
		long	FilterMode;	(0:none;1:transparent;2:blend;3:additive;4:addalpha;5:modulate)
		long	Shading;		//+1:unshaded;+2:SphereEnvMap;+16:twosided;
		long	TextureID;              //  +32:unfogged;+64:NoDepthTest;+128:NoDepthSet)
		long 	TVertexAnimId;		// 0xFFFFFFFF if none
		long	CoordId;
		float	Alpha;			(0(transparent)->1(opaque))
		(KMTA)
		(KMTF)				// state is long not float
	} layers[nlays];
 * @author madjk
 *
 */
public class MDXLayerCOM extends MDXParentCOM {
	int nbytesi = -1;
	public int filterMode = -1;
	public int shading = -1;
	public int textureID = -1;
	public int tVertextAnimID = -1;
	public int coordID = -1;
	public float alpha = -1;
	
	public MDXAlpha kmta;
	public MDXTextureID kmtf;
	
	public String getTag() {
		return "LAYS:layer";
	}
	
	public void _decode(LEDataInputStream ins) throws IOException, MDXException {
		nbytesi = ins.readInt();
		filterMode = ins.readInt();
		shading = ins.readInt();
		textureID = ins.readInt();
		tVertextAnimID = ins.readInt();
		coordID = ins.readInt();
		alpha = ins.readFloat();
		
		byte tagBytes[] = new byte[4];
		ins.read(tagBytes);
		String tag = new String(tagBytes);
		if(tag.equals("KMTA")) {
			kmta = new MDXAlpha();
			kmta.decode(ins);
		} else ins.unread(tagBytes);

		tagBytes = new byte[4];
		ins.read(tagBytes);
		tag = new String(tagBytes);
		if(tag.equals("KMTF")) {
			kmtf = new MDXTextureID();
			kmtf.decode(ins);
		} else ins.unread(tagBytes);
	}
		
	public String toString() {
		StringBuffer sb = new StringBuffer();
		sb.append("TAG : "+getTag());
		sb.append("\n\tNBYTESI : "+nbytesi);
		sb.append("\n\tFILTERMODE : "+filterMode);
		sb.append("\n\tSHADING : "+shading);
		sb.append("\n\tTEXTUREID : "+textureID);
		sb.append("\n\tTVERTEXTANIMID : "+tVertextAnimID);
		sb.append("\n\tCOORDID : "+coordID);
		sb.append("\n\tALPHA : "+alpha);
		sb.append("\n\tKMTA : "+ (kmta == null ? false : true) );
		sb.append("\n\tKMTF : "+ (kmtf == null ? false : true) );
		return sb.toString();
	}

	@Override
	public boolean isImplicitTag() {
		// TODO Auto-generated method stub
		return false;
	}
}